package com.example.casper.Experiment2024.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter4.BaseQuickAdapter;
import com.chad.library.adapter4.viewholder.QuickViewHolder;
import com.example.casper.Experiment2024.R;
import com.example.casper.Experiment2024.entity.LocationInfo;

import java.util.stream.Collectors;

public class PublishAdapter extends BaseQuickAdapter<LocationInfo, QuickViewHolder> {

    @Override
    protected void onBindViewHolder(@NonNull QuickViewHolder quickViewHolder, int i, @Nullable LocationInfo s) {
        quickViewHolder.setText(R.id.title, s.getTitle());
        quickViewHolder.setText(R.id.desc, s.getDesc());
        RecyclerView content = quickViewHolder.getView(R.id.content);
        PhotoAdapter adapter = new PhotoAdapter();
        adapter.submitList(s.getImage().stream().filter(ss -> ss.length() > 1).collect(Collectors.toList()));
        content.setAdapter(adapter);
    }

    @NonNull
    @Override
    protected QuickViewHolder onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_publish, viewGroup,
                false);
        return new QuickViewHolder(view);
    }
}
